<?php
	class settingAction extends userAction {
		protected $feedsetting = false;
		protected function _initialize() {
			parent::_initialize();
			$this->feedsetting = getAddFeedsetting($this->userInfo->id,"infoaction"); 
		}

		public function index(){
			$userInfo = D("user")->find("id=".$this->userInfo->id);
			$this->assign("userInfo",$userInfo);
			$this->display();
		}
		
		public function contact(){
			$userContactDao = D("user_contact");
			$userContact = $userContactDao->find("userid=".$this->userInfo->id);
			$this->assign("userContact",$userContact);
			$this->display();
		}
		
		public function my(){
			$record = D("user_info")->find("userid=".$this->userInfo->id);
			$this->assign("info",$record);
			$this->display();
		}
		
		public function edu(){
			$userEduDao = D("user_edu");
			$userHeightEdu = $userEduDao->findAll('school_type=1 and userid='.$this->userInfo->id,"*","regtime desc"); //大学信息
			$userMiddleEdu = $userEduDao->findAll('school_type=2 and userid='.$this->userInfo->id,"id,school_name,regtime","regtime desc");//中学信息
			$this->assign("userHeightEdu",$userHeightEdu);
			$this->assign("userMiddleEdu",$userMiddleEdu);
			$this->display();
		}
		
		public function work(){
			$userWorkDao = D("user_work");
			$userWork = $userWorkDao->findAll("userid=".$this->userInfo->id);
			$this->assign("userWork",$userWork);
			$this->display();
		}
		
		public function face(){
			$this->display();
		}
		
		public function savebaseinfo(){
			$baseInfoDao = D("user");
			$baseInfoDao->find($this->userInfo->id);
			$baseInfoDao->sex= $_POST["sex"];
			$baseInfoDao->birthday= strtotime($_POST["birthday"]);
			$baseInfoDao->birthday_mode= $_POST["birthday_mode"];
			$baseInfoDao->star= $_POST["star"];
			$baseInfoDao->hometown_city= $_POST["hometown_city"];
			$baseInfoDao->hometown_zone= $_POST["hometown_zone"];
			$baseInfoDao->save();
			/*$data["id"] = $this->userInfo->id;
			$data["sex"] = $_POST["sex"];
			$data["birthday"] = strtotime($_POST["birthday"]);
			$data["birthday_mode"] = $_POST["birthday_mode"];
			$data["star"] = $_POST["star"];
			$data["hometown_city"] = $_POST["hometown_city"];
			$data["hometown_zone"] = $_POST["hometown_zone"];
			$baseInfoDao->save($data);*/
			$userInfo = $baseInfoDao->find("id=".$this->userInfo->id);
			//Session::set("userInfo",$userInfo);
			F("userInfo",$userInfo,DATA_PATH.$this->userInfo->id);
			if($this->feedsetting){
				addFeed($this->userInfo->id,"editinfo","更新了基本信息");
			}
			$this->redirect("index");
			//$this->display("test");
		}
		
		public function savecontact(){
			$userContact = D("user_contact");
			$userContact->find("userid=".$this->userInfo->id);
			$userContact->qq = $_POST["qq"];
			$userContact->msn = $_POST["msn"];			
			$userContact->gtalk = $_POST["gtalk"];
			$userContact->skype = $_POST["skype"];
			$userContact->mobile = $_POST["mobile"];
			$userContact->tel = $_POST["tel"];
			$userContact->address = $_POST["address"];
			$userContact->homepage = $_POST["homepage"];
			if($userContact->save()){
				if($this->feedsetting){
					addFeed($this->userInfo->id,"editinfo","更新了联系方式");
				}
				$this->redirect("contact");
			}else{
				$this->error("操作失败，你可以重试一次。");
			}
			
		}
		
	
		public function saveface(){
			import("ORG.Net.UploadFile");
        	$upload = new UploadFile();
        	$upload->allowExts = array("jpg","gif","png");
			$path = getDeep($this->userInfo->id)."/";
        	$upload->savePath = "./Public/Uploads/face/".$path;
        	$upload->fileExtension = true; 
        	$upload->uploadReplace = true; //重名替换
        	$upload->fileExtension = true;
        	$upload->thumb = true;
        	$upload->thumbMaxWidth = "200,60";
        	$upload->thumbMaxHeight = "150,60";
        	$upload->saveRule = "uniqid";
        	$upload->thumbSuffix = "./Public/Uploads/face/big/".$path."/,./Public/Uploads/face/small/".$path."/";
        	if($upload->upload()){
        		$img = $upload->getUploadFileInfo();
        		D("user")->setField("faceimg",$path.$img[0]["savename"],"id=".$this->userInfo->id);//更新头像
				if($this->feedsetting){
					addFeed($this->userInfo->id,"editinfo","更换了头像");
				}
        		$this->redirect("index","user");
        	}else{
        		$this->error($upload->error);
        	}
		}
		
		public function savemy(){
			$myDao = D("user_info");
			$myDao->find("userid=".$this->userInfo->id);
			$myDao->interests = str_filter($_POST["interests"]);
            $myDao->musics = str_filter($_POST["musics"]);
            $myDao->movies = str_filter($_POST["movies"]);
            $myDao->cartoons = str_filter($_POST["artoons"]);
            $myDao->games = str_filter($_POST["games"]);
            $myDao->sports = str_filter($_POST["sports"]);
            $myDao->books = str_filter($_POST["books"]);
            $myDao->adage = str_filter($_POST["dage"]);
            $myDao->icon = str_filter($_POST["icon"]);
            $myDao->intro = str_filter($_POST["intro"]);
			if($myDao->save()){
				if($this->feedsetting){
					$content = "更新了个人兴趣爱好";
					addFeed($this->userInfo->id,"editinfo",$content);
				}
				$this->success("保存信息成功");
			}else{
				$this->error("操作失败，你可以重试一次");
			}
		}
		
		public function privacy(){
			$dao = D("user_setting");
			$privacy = $dao->find("userid=".$this->userInfo->id);
			$this->assign("privacy",$privacy);
			$this->display();
		}
	}
?>